﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoccaStore.Enums;
using RoccaStore.Utils;

namespace RoccaStore
{
    public class Slug
    {
        [Key]
        [Column("SlugID")]
        public int ID { get; set; }

        public int? ParentID { get; set; }

        public int? FileID { get; set; }

        public string Name { get; set; }

        public string Title { get; set; }

        public string Description { get; set; }

        public SlugType Type { get; set; }       

        public string Key { get; set; }

        public int Downloaded { get; set; }

        public int Expiry { get; set; }

        public bool IsSecure { get; set; }

        public string Password { get; set; }

        public DateTime? Deleted { get; set; }

        [ForeignKey("ParentID")]
        public virtual Slug Parent { get; set; }

        [ForeignKey("FileID")]
        public virtual FileInfo File { get; set; }

        [InverseProperty("Parent")]
        public virtual ICollection<Slug> Files { get; set; }

        public void GenerateSlug()
        {
            IsSecure = false;
            Key = SecurityUtils.HashEncrypt(ID.ToString());
            Name = HashUtils.Encode(ID);
        }        
    }
}
